<?php

// $pag = preg_replace ( "/<!-- *REPLACE: (?<nome>[^ ]*) (.*) *-->.*<!-- *ENDREPLACE: \k<nome>[ \t]*-->/U", "$2", $pag );

function _apply_regex ( $pag, $bn )
{
	$pag = str_replace ( array ( "\n", "\t", "\r" ), "", $pag );

	$pag = preg_replace ( "/.*<body[^>]*>(.*)<\/body>.*/i", "$1", $pag );

	if ( $bn )
		$pag = preg_replace ( "/.*<!-- {{{ BLK: $bn -->(.*)<!-- }}} $bn -->(.*)$/Ui", "$1", $pag );

	$pag = preg_replace ( "/<!-- {{{ REP: (?<nome>[^ ]*) (.*) -->.*<!-- }}} \k<nome> -->/U", "$2", $pag );
	$pag = preg_replace ( "/<!--.*-->/U", "", $pag );

	return $pag;
}

$pag = file_get_contents ( "layman.html" );
print "--- $pag\n";
print "-------------------------------------------------\n";
print _apply_regex ( $pag, "pippo" );
print "\n";
print _apply_regex ( $pag, "block2" );
print "\n";
print _apply_regex ( $pag );
?>
